package day08Test;

import java.util.Random;
import java.util.Scanner;
//比较两个数组 并记录有多少相同的数
public class Test2 {
    public static void main(String[] args) {
        int[] arr = creatNumber();
        for (int i = 0; i < arr.length ; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        int[] userInputArr = userInputNumber();
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < userInputArr.length - 1; i++) {
            int redNumber = userInputArr[i];
            for (int j = 0; j < arr.length -1; j++) {
                if (arr[j] == redNumber){
                    ++redCount;
                    break;
                }
            }
        }
        int blueNumber = userInputArr[userInputArr.length-1];
        if (blueNumber == arr[arr.length-1]){
            blueCount++;
        }
        System.out.println("红球中奖个数为" + redCount);
        System.out.println("蓝球中奖个数为" + blueCount);
        //判断中了几等奖
        if (redCount == 6 && blueCount == 1){
            System.out.println("恭喜你，中奖1000万");
        }else if (redCount == 6 && blueCount == 0){
            System.out.println("恭喜你，中奖500万");
        }else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你，中奖3000");
        }else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)){
                System.out.println("恭喜你，中奖200");
    }else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)){
            System.out.println("恭喜你，中奖10");
        }else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)){
            System.out.println("恭喜你，中奖5");
        }else {
            System.out.println("抱歉，没有中奖");
        }
    }

//记录选中的号码
    public static int[] userInputNumber() {
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length - 1; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int redNumber = sc.nextInt();
            if (redNumber >= 1 && redNumber <= 33) {
                boolean flag = flag(arr, redNumber);
                if (!flag) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("当前输入的数字重复,请重新输入");
                }
            } else {
                System.out.println("当前输入号码超出范围，请重新输入");
            }
        }
        System.out.println("请输入蓝球号码");
        int blueNumber = sc.nextInt();
        while (true) {
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("当前输入号码超出范围，请重新输入");
            }
        }
        return arr;
    }


//记录随机中奖数组
    public static int[] creatNumber() {
        int[] arr = new int[7];
        Random r = new Random();

        for (int i = 0; i < 6; ) {
            int redNumber = r.nextInt(33) + 1;
            boolean flag = flag(arr, redNumber);
            if (!flag) {
                arr[i] = redNumber;
                i++;
            }
        }
        int blueNumber = r.nextInt(16) + 1;
        arr[arr.length - 1] = blueNumber;
        return arr;

    }

    //判断数组中 是否有这个数
    public static boolean flag(int[] arr, int number) {
        for (int i = 0; i < 6; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }
}

